import 'package:flutter/material.dart';

class DismissableExps extends StatefulWidget {
  DismissableExps({super.key});

  final items = List<String>.generate(5, (i) => 'Item ${i + 1}');

  @override
  State<DismissableExps> createState() => _DismissableExpsState();
}

class _DismissableExpsState extends State<DismissableExps> {
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: SafeArea(
        child: ListView.builder(
          itemCount: widget.items.length,
          itemBuilder: (context, index) {
            return Dismissible(
              key: UniqueKey(),
              background: Container(
                padding: EdgeInsets.only(right: 20),
                color: Colors.red,
                alignment: Alignment.centerRight,
                child: Icon(Icons.delete),
              ),
              onDismissed: (direction) {
                setState(() {
                  widget.items.removeAt(index);
                });
              },
              child: ListTile(
                title: Text(
                  widget.items[index],
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
